package com.trainoo.novel.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class ExceptionAdvice {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @ExceptionHandler(value = NovelException.class)
    @ResponseStatus(HttpStatus.OK)
    public String exception(NovelException e) {
        logger.error("系统[{}]时出现异常：{}", e.getType(), e);
        return "500";
    }
    
    @ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.OK)
    public String exception(Exception e) {
        logger.error("系统出现异常：{}", e);
        return "500";
    }

}
